using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace PDOGenerator.MapTypes
{
    class DataTypeMap
    {
        public static List<string> NullableTypes;
        public static Dictionary<string, Database> Databases;

        static DataTypeMap()
        {
            NullableTypes = new List<string>();
            NullableTypes.Add("decimal");
            NullableTypes.Add("sbyte");
            NullableTypes.Add("byte");
            NullableTypes.Add("short");
            NullableTypes.Add("ushort");
            NullableTypes.Add("int");
            NullableTypes.Add("uint");
            NullableTypes.Add("long");
            NullableTypes.Add("ulong");
            NullableTypes.Add("char");
            NullableTypes.Add("Int16");
            NullableTypes.Add("Int32");
            NullableTypes.Add("Int64");

            NullableTypes.Add("Guid");
            NullableTypes.Add("DateTime");

            Databases = new Dictionary<string, Database>();

            if (!Directory.Exists(".\\Schemas"))
            {
                // designer
                Databases.Add("SQLServer", null);
                return;
            }

            string[] Files = Directory.GetFiles(".\\Schemas", "DB.*.xml");
            XmlSerializer dbs = new XmlSerializer(typeof(Database));
            foreach (string f in Files)
            {
                string s = f.Substring(13, f.Length - 17);

                Stream fs = File.OpenRead(f);
                Databases.Add(s, (Database)dbs.Deserialize(fs));
                fs.Close();
            }
        }
    }
}
